<!DOCTYPE HTML>
<html>
<HEAD>
<meta charset="utf-8">
<TITLE>员工管理</TITLE>
</HEAD>
<body>
    
<?php
include_once("base-class.php");
include_once('DB.php');

$DB = new DB();

//获取当前页码
$page=intval($_GET["page"]);

//获取操作标识传入
$action=$_GET["action"];
$action= string::un_script_code($action);
$action= string::un_html($action);

//是否删除
if($action=="del")
{
    //获取员工ID号传入
    $roster_id=intval($_GET["roster_id"]);
    //获取当前时间
    $nowtime=date("Y/m/d H:i:s",time());
   	$DB->query("update roster set status=0,edittime='$nowtime' where roster_id=$roster_id");    
    echo "<script>alert('操作成功！');location='roster_manager.php?page=$page';</Script>";
    exit;    
}    
//列表数据获取、分页

//计算总数
$res=$DB->query("select * from roster where status=1");
$count = mysql_num_rows($res);

//如果数据表里有数据
if($count)
{
    //每页显示记录数
    $page_num = 10;
    //如果无页码参数则为第一页
    if ($page == 0) $page = 1;
    //计算开始的记录序号
    $from_record = ($page - 1) * $page_num;
    //获取符合条件的数据
    
    
//如果用户指定部门查询则
    if($_GET["class_id"]){

        $class_id = $_GET["class_id"];
//               $roster_list=$DB->get_all("select A.*,B.class_name
//                from roster A left join class B on A.roster_class=B.class_id where A.status=1 and A.class = $class
//                order by A.roster_id desc ");
        
         $roster_list=$DB->get_all("select A.*,B.class_name
                from roster A left join class B on A.roster_class=B.class_id where A.status=1 and A.roster_class = '{$class_id}'
                order by A.roster_id desc 
                limit $from_record,$page_num");
    }else{
        $roster_list=$DB->get_all("select A.*,B.class_name
                from roster A left join class B on A.roster_class=B.class_id where A.status=1 
                order by A.roster_id desc 
                limit $from_record,$page_num");
    }
    
    //分页函数
    $multi = multi($count, $page_num, $page, "roster_manager.php");
}
?>
     <b>华视文化公司通讯录管理</b>
    <!--页面名称-->
	<h3>员工管理<a href="roster_add.php">新增员工>></a></h3>
    <!--列表开始-->
    
    <table border=1>
        <tr bgcolor='gray'>
            <td>姓名</td><td>工号</td><td>照片</td><td>性别</td><td>部门</td><td>手机</td><td>邮箱</td><td>状态</td><td>操作</td>
        </tr>
        <?php
	    if($roster_list)
            {
                $roster_status_arr=array('',"在职","休假","试用期","离职");
                foreach($roster_list as $value)
                {
                    
                    $value["roster_sex"]=($value["roster_sex"]==1)?"男":"女";
                    $value["roster_status"]=$roster_status_arr[$value["roster_status"]];
                    $value["roster_openid"]=($value["roster_openid"]=="")?"未绑定":"已绑定";
                                             
                    echo "<tr>
                          <td> <a href='detail.php?roster_id=$value[roster_id]'>$value[roster_name]</td>
                          <td>$value[roster_number]</td>            
                          <td><img src=\"$value[roster_pic]\" height=\"150\"></td>
                          <td>$value[roster_sex]</td>
                          <td>$value[class_name]</td>
                          <td>$value[roster_mp]</td>
                          <td>$value[roster_mail]</td>
                          <td>$value[roster_status]</td>
                          <td>
                            <a href='roster_manager.php?action=del&roster_id=$value[roster_id]'>删除</a>
                            <a href='roster_add.php?roster_id=$value[roster_id]'>修改</a>
                          </td>
                          <tr>";
                    
                }
            }
			else
            {
                echo "<tr><td colspan=8>无记录</td></tr>";
            }
        ?>
    
    </table>
    <?php
	echo $multi;
    ?>
</body>
</html>
